from django.db import models

IS_ACTIVE = (
    (True, "是"),
    (False, "否"),
)


class Statistics(models.Model):
    """
    数据统计
    """
    ip = models.CharField(max_length=20, verbose_name="ip", db_column="ip", default=None, null=True, blank=True)

    # , unique = True
    access_time = models.DateTimeField(verbose_name="访问时间", db_column="访问时间", null=True, blank=True, auto_now=True)
    access_date = models.DateField(verbose_name="访问日期", db_column="访问日期", null=True, blank=True, auto_now_add=True)


    # 做统计图表的测试数据
    # access_time = models.DateTimeField(verbose_name="访问时间", db_column="访问时间", null=True, blank=True)
    # access_date = models.DateField(verbose_name="访问日期", db_column="访问日期", null=True, blank=True)

    mobile = models.BooleanField(choices=IS_ACTIVE, default=False, blank=True, null=True, verbose_name='手机端访问', db_column='手机端访问')

    # unique_identifier = models.CharField(max_length=40, verbose_name="唯一标识符", db_column="唯一标识符", default=None, null=True, blank=True)    # , unique=True
    class Meta:
        ordering = ('-id', )
        verbose_name_plural = verbose_name = "访问记录表"
        db_table = '访问记录表'

    # def save(self, *args, **kwargs):  # 这里要设置唯一标识符, 防止并发重复创建... 后面再弄吧
    #     if not self.unique_identifier:
    #         self.unique_identifier = str(self.ip) + "__" + str(self.access_date)
    #     return super().save(*args, **kwargs)


class ViewsByDayModel(Statistics):  # 父类为要展示的model类
    class Meta:
        proxy = True  # 使用代理
        verbose_name_plural = verbose_name = '流量统计图'
